/* 
 * time.h
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is a part of the clang port package.
 * No warranty is given; refer to the file DISCLAIMER within the package.
 *
 * Date and time functions and types.
 *
 */

#ifndef	_CLANG_PORT_TIME_H_
#define	_CLANG_PORT_TIME_H_

/* All the headers include this file. */
#ifndef __IMPL_CLANG_PORT_API_
#	include <_clang_port.h>
#else
#	include <include/_clang_port.h>
#endif

#include <stddef.h>

#ifndef __IMPL_CLANG_PORT_API_
/*
 * Number of clock ticks per second. A clock tick is the unit by which
 * processor time is measured and is returned by 'clock'.
 */
#define	CLOCKS_PER_SEC	((clock_t)1000)
#define	CLK_TCK		CLOCKS_PER_SEC

typedef	long	time_t;
typedef	long	clock_t;

struct tm
{
	int	tm_sec;		/* Seconds: 0-59 (K&R says 0-61?) */
	int	tm_min;		/* Minutes: 0-59 */
	int	tm_hour;	/* Hours since midnight: 0-23 */
	int	tm_mday;	/* Day of the month: 1-31 */
	int	tm_mon;		/* Months *since* january: 0-11 */
	int	tm_year;	/* Years since 1900 */
	int	tm_wday;	/* Days since Sunday (0-6) */
	int	tm_yday;	/* Days since Jan. 1: 0-365 */
	int	tm_isdst;	/* +1 Daylight Savings Time, 0 No DST,
				 * -1 don't know */
};
#endif // __IMPL_CLANG_PORT_API_

#ifdef	__cplusplus
extern "C" {
#endif
/* 
 * Clang Hook Api.
*/
	typedef clock_t CLANG_PORT_FPTR_TYPE(clock)(void);
	extern CLANG_PORT_FPTR_VAR(clock);
	typedef time_t CLANG_PORT_FPTR_TYPE(time)(time_t*);
	extern CLANG_PORT_FPTR_VAR(time);
	typedef double CLANG_PORT_FPTR_TYPE(difftime)(time_t, time_t);
	extern CLANG_PORT_FPTR_VAR(difftime);
	typedef time_t CLANG_PORT_FPTR_TYPE(mktime)(struct tm*);
	extern CLANG_PORT_FPTR_VAR(mktime);
	typedef char* CLANG_PORT_FPTR_TYPE(asctime)(const struct tm*);
	extern CLANG_PORT_FPTR_VAR(asctime);
	typedef char* CLANG_PORT_FPTR_TYPE(ctime)(const time_t*);
	extern CLANG_PORT_FPTR_VAR(ctime);
	typedef struct tm* CLANG_PORT_FPTR_TYPE(gmtime)(const time_t*);
	extern CLANG_PORT_FPTR_VAR(gmtime);
	typedef struct tm* CLANG_PORT_FPTR_TYPE(localtime)(const time_t*);
	extern CLANG_PORT_FPTR_VAR(localtime);
	typedef size_t CLANG_PORT_FPTR_TYPE(strftime)(char*, size_t, const char*, const struct tm*);
	extern CLANG_PORT_FPTR_VAR(strftime);

#ifndef __IMPL_CLANG_PORT_API_
/*
 * STD C Api.
 */
CLANG_PORT_INLINE clock_t clock (void)
{
	return CLANG_PORT_CALL_FPTR(clock)();
}
CLANG_PORT_INLINE time_t time (time_t* t)
{
	return CLANG_PORT_CALL_FPTR(time)(t);
}
CLANG_PORT_INLINE double difftime (time_t t1, time_t t2)
{
	return CLANG_PORT_CALL_FPTR(difftime)(t1,t2);
}
CLANG_PORT_INLINE time_t mktime (struct tm* t)
{
	return CLANG_PORT_CALL_FPTR(mktime)(t);
}
CLANG_PORT_INLINE char* asctime (const struct tm* t)
{
	return CLANG_PORT_CALL_FPTR(asctime)(t);
}
CLANG_PORT_INLINE char* ctime (const time_t* t)
{
	return CLANG_PORT_CALL_FPTR(ctime)(t);
}
CLANG_PORT_INLINE struct tm*  gmtime (const time_t* t)
{
	return CLANG_PORT_CALL_FPTR(gmtime)(t);
}
CLANG_PORT_INLINE struct tm* localtime (const time_t* t)
{
	return CLANG_PORT_CALL_FPTR(localtime)(t);
}
CLANG_PORT_INLINE size_t strftime (char* ptr, size_t size, const char* format, const struct tm* t)
{
	return CLANG_PORT_CALL_FPTR(strftime)(ptr,size,format,t);
}
#endif /* __IMPL_CLANG_PORT_API_ */

#ifdef	__cplusplus
}
#endif


#endif	/* Not _CLANG_PORT_TIME_H_ */

